package com.bestcem.xm.om.grpc.service.converter;

import com.bestcem.xm.om.entity.OmIndustry;
import com.bestcem.xm.om.grpc.v1.services.Industry;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * grpc请求出入参转化类
 *
 * @author zhangfeng <feng.zhang@idiaoyan.com>
 * @version v1.0
 * @date 2022/1/11 10:11
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class IndustryConverter {
    /**
     * grpc请求入参转换成本地入参：行业
     *
     * @param industry
     * @return com.bestcem.xm.om.grpc.service.param.statistics.OmAuthParam
     * @author zhangfeng <feng.zhang@idiaoyan.com>
     * @date 2021/12/31 11:02
     */
    public static OmIndustry requestToParam(Industry industry) {
        OmIndustry omIndustry = new OmIndustry();
        omIndustry.setId(industry.getId());
        omIndustry.setName(industry.getName());
        omIndustry.setCode(industry.getCode());
        omIndustry.setQrCode(industry.getQrCode());
        omIndustry.setOrder(industry.getOrder());
        return omIndustry;
    }

    /**
     * grpc请求入参转换成本地入参：行业
     *
     * @param omIndustry
     * @return com.bestcem.xm.om.grpc.service.param.statistics.OmAuthParam
     * @author zhangfeng <feng.zhang@idiaoyan.com>
     * @date 2021/12/31 11:02
     */
    public static Industry entityToDto(OmIndustry omIndustry) {
        if(Objects.isNull(omIndustry)){
            return null;
        }
        Industry.Builder builder = Industry.newBuilder();

        if (StringUtils.isNotBlank(omIndustry.getId())) {
            builder.setId(omIndustry.getId());
        }
        if (StringUtils.isNotBlank(omIndustry.getName())) {
            builder.setName(omIndustry.getName());
        }
        if (Objects.nonNull(omIndustry.getCode())) {
            builder.setCode(omIndustry.getCode());
        }
        if (StringUtils.isNotBlank(omIndustry.getQrCode())) {
            builder.setQrCode(omIndustry.getQrCode());
        }
        if (Objects.nonNull(omIndustry.getOrder())) {
            builder.setOrder(omIndustry.getOrder());
        }
        return builder.build();
    }
}
